/* 
 * Copyright 2014 ShangDao.Ltd  All rights reserved.
 * SiChuan ShangDao.Ltd PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * 
 * @ActActiveDetail.java  2014年9月10日 上午11:23:31 - Guzhu
 * @author Guzhu
 * @email:muyi126@163.com
 * @version 1.0
 */

package com.android.tiango.baba.act;

import java.util.ArrayList;

import org.yanzi.ui.HorizontalListView;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSONObject;
import com.android.scsd.tiango.R;
import com.android.support.httpclient.HttpCallBack;
import com.android.support.httpclient.HttpClientAsync;
import com.android.support.httpclient.HttpParams;
import com.android.tiango.baba.BaBaseApplication;
import com.android.tiango.baba.BaListActivity;
import com.android.tiango.baba.adapter.BaHeaderAdapter;
import com.android.tiango.baba.adapter.CardDetailAdapter;
import com.android.tiango.baba.cookie.HttpUrl;
import com.android.tiango.baba.cookie.ShareCookie;
import com.android.tiango.baba.entity.ActivityModel;
import com.android.tiango.baba.entity.BaseDataEntity;
import com.android.tiango.baba.entity.BaseEntity;
import com.android.tiango.baba.entity.ProductModel;
import com.android.tiango.baba.entity.ProductTopicModel;
import com.android.tiango.baba.entity.PropertyModel;
import com.android.tiango.baba.entity.ReplyEntity;
import com.android.tiango.baba.entity.ReplyModel;
import com.android.tiango.baba.entity.SimpleUserEntity;
import com.android.tiango.baba.entity.SimpleUserModel;
import com.android.tiango.baba.util.Constants;
import com.android.tiango.baba.util.StringUtils;
import com.android.tiango.baba.util.TimeToUtil;
import com.android.tiango.baba.util.ToastUtils;
import com.android.tiango.baba.view.ActivePullListView;
import com.android.tiango.baba.view.MeasureGridView;
import com.android.tiango.baba.view.TopDotPager;
import com.android.tiango.baba.view.TopDotPager.OnItemClickListener;

/**
 * 活动详情页
 * @author givon
 * 
 */
public class ActActiveDetail extends BaListActivity<ReplyModel> implements
		ActivePullListView.PullListViewListener,
		com.android.tiango.baba.BaListActivity.AddHeaderViewCallBack, OnClickListener {
	private View mHeaderView;
	private TopDotPager mTopDotPager;
	private TextView mNewPrice;
	private TextView mOldPrice;
	private TextView mActiveName;
	private LinearLayout mLy_Property;
	private HorizontalListView mHorizontalListView;
	private TextView mTitle;
	private ImageView mBackView;
	private LinearLayout mLLTimeLayout;
	private RelativeLayout mReQgLayout;
	private RelativeLayout mReHfLayout;
	private boolean isQiangGou = true;
	private ImageView mIvHuifu;
	private EditText mEditText;
	private ImageView mIvQingGou;
	private Button mQGouButton;
	private ActivePullListView mListView;
	private String mBarId;
	private String mTopicId;
	private ProductModel mProductModel;
	private ArrayList<ActivityModel> mActivityModels;
	private ActivityModel mActivityModel;
	private ArrayList<SimpleUserModel> mUserModels;
	private TextView mTvDaoJiShi;
	private TextView mTvDaoJiInfo;
	private long mServerTime;
	private CountDownListener countDownListener;
	private TimeCount mStarTimeCount;
	private TimeEndCount mTimeEndCount;
	private ArrayList<ReplyModel> mReplyModels;
	private ImageView mIv_Like;

	@Override
	protected void onCreate(Bundle arg0) {
		super.onCreate(arg0);
		setContentView(R.layout.layout_active_detail);
		Intent intent = getIntent();
		if (intent.hasExtra("BarId") && intent.hasExtra("TopicId")) {
			mBarId = intent.getStringExtra("BarId");
			mTopicId = intent.getStringExtra("TopicId");
			mServerTime = BaBaseApplication.getmServerTime();
			initView();
			mListView.setPullListener(this);
			loadProductTopicDetail();
			mListView.startLoadMore();
		}else{
			this.finish();
		}
	}

	private void initView() {
		mAdapter = new ListAdapter(this);
		mListView = (ActivePullListView) findViewById(R.id.id_pull_listview);
		mTitle = (TextView) findViewById(R.id.titlebar_title);
		mListView.setHeaderDividersEnabled(false);
		mListView.setFooterDividersEnabled(false);
		mLLTimeLayout = (LinearLayout) findViewById(R.id.ll_1);
		mLLTimeLayout.setVisibility(View.GONE);
		mReQgLayout = (RelativeLayout) findViewById(R.id.include_1);
		mIvHuifu = (ImageView) mReQgLayout.findViewById(R.id.iv_huifu);
		mReHfLayout = (RelativeLayout) findViewById(R.id.include_2);
		mTvDaoJiShi = (TextView) mReQgLayout.findViewById(R.id.tv_Time);
		mTvDaoJiInfo = (TextView) mReQgLayout.findViewById(R.id.tv_qgInfo);
		mEditText = (EditText) mReHfLayout.findViewById(R.id.et_msg);
		mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
			@Override
			public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
				if (!StringUtils.isEmpty(mEditText.getText().toString())) {

					if (actionId == EditorInfo.IME_ACTION_SEND) {
						/* 隐藏软键盘 */
						loadReplyTheProductTopic(mEditText.getText().toString());
						InputMethodManager imm = (InputMethodManager) v.getContext()
								.getSystemService(Context.INPUT_METHOD_SERVICE);
						if (imm.isActive()) {
							imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0);
						}
						return true;
					}
				} else {
					ToastUtils.showMessage(getStringValue(R.string.info_Reply_not_null));
				}
				return false;
			}
		});
		mIv_Like = (ImageView) findViewById(R.id.image_like);
		mIv_Like.setOnClickListener(this);
		mIvQingGou = (ImageView) mReHfLayout.findViewById(R.id.iv_qg);
		mIvHuifu.setOnClickListener(this);
		mIvQingGou.setOnClickListener(this);
		mQGouButton = (Button) mReQgLayout.findViewById(R.id.bt_qinggou);
		mQGouButton.setOnClickListener(new NotStartListener());
		setHeaderView(this);
		mListView.setSelector(android.R.color.transparent);
		if (null != addHeaderViewCallBack) {
			addHeaderViewCallBack.addHeaderView();
		}
		mBackView = (ImageView) findViewById(R.id.image_back);
		mBackView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				onBackPressed();
			}
		});
		mTopDotPager.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClickListener(int position) {

				// showActivity(ActShowOrder.class, false);
				if (null != mProductModel) {

					Intent intent = new Intent(ActActiveDetail.this, ActShowOrder.class);
					intent.putExtra(Constants.DATA, mProductModel);
					startActivity(intent);
				}
			}
		});
		mListView.setAdapter(mAdapter);
		setCountDownListener(new CountDownListener() {

			@Override
			public void heartBest() {

			}

			@Override
			public void countDownStart() {
				mQGouButton.setOnClickListener(new StartListener());
			}

			@Override
			public void countDownEnd() {
				mQGouButton.setOnClickListener(new EndListener());
			}
		});
	}

	@Override
	protected View getItemView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		ReplyModel model = mAdapter.getItem(position);
		if (null == convertView) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(ActActiveDetail.this).inflate(
					R.layout.item_carddetail, null);
			holder.iv_acthead = (ImageView) convertView.findViewById(R.id.iv_acthead);
			holder.tv_acttitle = (TextView) convertView.findViewById(R.id.tv_acttitle);
			holder.iv_sex = (ImageView) convertView.findViewById(R.id.iv_sex);
			holder.iv_thelord = (ImageView) convertView.findViewById(R.id.iv_thelord);
			holder.tv_time = (TextView) convertView.findViewById(R.id.tv_time);
			holder.tv_replyname = (TextView) convertView.findViewById(R.id.tv_replyname);
			holder.tv_flor = (TextView) convertView.findViewById(R.id.tv_flor);
			holder.tv_replycontent = (TextView) convertView.findViewById(R.id.tv_replycontent);
			holder.tv_actinfo = (TextView) convertView.findViewById(R.id.tv_actinfo);
			holder.ml_gridview = (MeasureGridView) convertView.findViewById(R.id.ml_gridview);
			holder.ll_reply = (LinearLayout) convertView.findViewById(R.id.ll_reply);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		if (null != model) {
			// 主用户
			SimpleUserModel replyUser = model.getReplyUser();
			SimpleUserModel commentUser = model.getCommentUser();
			if (null != replyUser) {
				mImageLoader.loadImage(replyUser.getAvatarUrl(), holder.iv_acthead);
				holder.tv_acttitle.setText(replyUser.getNickName());
				switch (replyUser.getGender()) {
				case 0:
					// 未设置
					holder.iv_sex.setVisibility(View.INVISIBLE);
					break;
				case 1:
					// 男
					holder.iv_sex.setVisibility(View.VISIBLE);
					holder.iv_sex.setBackgroundDrawable(getResources().getDrawable(
							R.drawable.bg_sex));
					break;
				case 2:
					// 女
					holder.iv_sex.setVisibility(View.VISIBLE);
					holder.iv_sex.setBackgroundDrawable(getResources().getDrawable(
							R.drawable.bg_sex_girl));
					break;
				default:
					break;
				}
				if (model.getIsBarOwner() == 1) {
					holder.iv_thelord.setVisibility(View.VISIBLE);
				} else {
					holder.iv_thelord.setVisibility(View.INVISIBLE);
				}
				if (model.getIsTopicOwner() == 1) {
					holder.tv_flor.setVisibility(View.VISIBLE);
				} else {
					holder.tv_flor.setVisibility(View.INVISIBLE);
				}
				holder.tv_actinfo.setText(StringUtils.getDefaultString(model.getReplyContent()));
				holder.tv_replycontent.setText(StringUtils.getDefaultString(model
						.getCommentContent()));
				if (null != commentUser) {
					holder.ll_reply.setVisibility(View.VISIBLE);
					holder.tv_replyname.setText("回复" + model.getCommentFloorNo() + "楼");
				} else {
					holder.ll_reply.setVisibility(View.GONE);
				}
				holder.tv_time.setText(TimeToUtil.getSystemTimeSetFormat(model.getCreateTime(),
						TimeToUtil.ACCURATE_TO_THE_DAY));
				CardDetailAdapter cardAdapter = new CardDetailAdapter(ActActiveDetail.this);
				holder.ml_gridview.setAdapter(cardAdapter);
				holder.ml_gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
					public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
						Intent intent = new Intent(ActActiveDetail.this, ActImgBrowse.class);
						String[] value = {
								"http://a.hiphotos.baidu.com/image/w%3D310/sign=7ca3586037a85edffa8cf822795509d8/bba1cd11728b47107980ccfcc0cec3fdfc032356.jpg",
								"http://e.hiphotos.baidu.com/image/pic/item/aec379310a55b319c7d37aa641a98226cffc173e.jpg",
								"http://img0.bdstatic.com/img/image/shouye/mxlmh-9420812562.jpg",
								"http://img0.bdstatic.com/img/image/shouye/mxtly-11896748157.jpg" };
						intent.putExtra("urls", value);
						startActivity(intent);
					}

				});

			}
		}

		return convertView;
	}

	class ViewHolder {
		private ImageView iv_acthead;
		private TextView tv_acttitle;
		private ImageView iv_sex;
		private ImageView iv_thelord;
		private TextView tv_time;
		private TextView tv_flor;
		private TextView tv_actinfo;
		private MeasureGridView ml_gridview;
		private TextView tv_replyname;
		private TextView tv_replycontent;
		private LinearLayout ll_reply;

	}

	@Override
	public void addHeaderView() {
		mHeaderView = getLayoutInflater().inflate(R.layout.header_active_detail, null);
		mTopDotPager = (TopDotPager) mHeaderView.findViewById(R.id.tp_TopPage);
		mTopDotPager.setImageLoader(mImageLoader);
		mNewPrice = (TextView) mHeaderView.findViewById(R.id.tv_newPrice);
		mOldPrice = (TextView) mHeaderView.findViewById(R.id.tv_oldPrice);
		mOldPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
		mActiveName = (TextView) mHeaderView.findViewById(R.id.tv_name);
		mLy_Property = (LinearLayout) mHeaderView.findViewById(R.id.ly_goodsProperty);
		mHorizontalListView = (HorizontalListView) mHeaderView.findViewById(R.id.horizon_listview);
		mListView.addHeaderView(mHeaderView);
	}

	@Override
	public void onPullRefresh() {
		loadProductActivities();
	}

	@Override
	public void onPullLoadMore() {
		loadData();
	}

	private void loadData() {
		loadProductTopicReplies();
	}

	private void initViewData() {
		if (null != mProductModel) {
			mNewPrice.setText(mProductModel.getTgoPrice() + "");
			mOldPrice.setText(mProductModel.getMarketPrice() + "");
			mActiveName.setText(mProductModel.getProductName());
			mLy_Property.removeAllViews();
			if (null != mProductModel.getProperties()) {
				for (int i = 0; i < mProductModel.getProperties().size(); i++) {
					PropertyModel propertyBean = mProductModel.getProperties().get(i);
					TextView textView = new TextView(this);
					AbsListView.LayoutParams lp = new AbsListView.LayoutParams(-1, -2);
					textView.setLayoutParams(lp);
					textView.setTextSize(14);
					textView.setTextColor(getResources().getColor(R.color.font_black_1));
					textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
					textView.setPadding(24, 8, 8, 8);
					textView.setText(propertyBean.getPropertyName() + ": "
							+ propertyBean.getPropertyValue());
					if (null != mLy_Property) {
						mLy_Property.addView(textView);
					}
				}
			}
		}

	}

	private void initTimer(long startTime, long endTiem, ActivityModel model) {
		if (mServerTime > endTiem || model.getRemainNumber() <= 0) {
			// 活动结束
			// mCountDownBean.setRemainCount(0);
			mTvDaoJiShi.setText("00:00:00");
			mTvDaoJiShi.setVisibility(View.INVISIBLE);
			mTvDaoJiInfo.setText(getString(R.string.text_rob_end));
			if (null != countDownListener) {
				countDownListener.countDownEnd();
			}
		} else {
			// 活动没有结束
			if (mServerTime < startTime) {
				// 活动没有开始，启动倒计时
				if (null != mStarTimeCount) {
					mStarTimeCount.cancel();
					mStarTimeCount = new TimeCount(startTime - mServerTime, 10);
				} else {
					mStarTimeCount = new TimeCount(startTime - mServerTime, 10);
				}
				mStarTimeCount.start();
			} else if (mServerTime > startTime && mServerTime < endTiem) {
				// 活动开始，还没有结束，启动结束倒计时
				if (null != mTimeEndCount) {
					mTimeEndCount.cancel();
					mTimeEndCount = new TimeEndCount(endTiem - mServerTime, 1000);

				} else {
					mTimeEndCount = new TimeEndCount(endTiem - mServerTime, 1000);
				}
				mTvDaoJiShi.setText("00:00:00");
				mTvDaoJiShi.setVisibility(View.INVISIBLE);
				mTvDaoJiInfo.setText(getString(R.string.text_paying));
				mTimeEndCount.start();
				if (null != countDownListener) {
					countDownListener.countDownStart();
				}
			} else {
				// 活动已经结束
				mTvDaoJiShi.setText("00:00:00");
				mTvDaoJiShi.setVisibility(View.INVISIBLE);
				mTvDaoJiInfo.setText(getString(R.string.text_rob_end));
				if (null != countDownListener) {
					countDownListener.countDownEnd();
				}
			}
		}

	}

	private void initReLayout() {
		if (isQiangGou) {
			mReQgLayout.setVisibility(View.VISIBLE);
			mReHfLayout.setVisibility(View.GONE);
		} else {
			mReQgLayout.setVisibility(View.GONE);
			mReHfLayout.setVisibility(View.VISIBLE);
		}
	}

	/**
	 * 还没有开始
	 * @author givon
	 * 
	 */
	private class NotStartListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			showActivity(ActFailDialog.class, ActFailDialog.NOT_START);
		}

	}

	/**
	 * 开始抢购
	 * @author givon
	 * 
	 */
	private class StartListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			loadRushToGetProduct(mActivityModel.getActivityId());
			mQGouButton.setOnClickListener(null);
		}
	}

	/**
	 * 抢完
	 * @author givon
	 * 
	 */
	private class EndListener implements OnClickListener {
		@Override
		public void onClick(View v) {
			showActivity(ActFailDialog.class, ActFailDialog.QIANG_WANG);
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.iv_huifu:
			isQiangGou = false;
			initReLayout();
			break;
		case R.id.iv_qg:
			isQiangGou = true;
			initReLayout();
			break;
		case R.id.bt_qinggou:
			// 看抢到没有

			break;
		case R.id.image_like:
			// 看抢到没有
			loadCollectTopic();
			break;

		default:
			break;
		}

	}

	public interface CountDownListener {
		void countDownStart();

		void countDownEnd();

		void heartBest();
	}

	private void setCountDownListener(CountDownListener l) {
		this.countDownListener = l;

	}

	class TimeCount extends CountDownTimer {

		private int countSec = 10;

		public TimeCount(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);
		}

		@Override
		public void onTick(long millisUntilFinished) {
			int sec = (int) (millisUntilFinished / 1000);
			mTvDaoJiShi.setText(TimeToUtil.getCountDown(millisUntilFinished));
			if (sec <= 10 && sec > 0) {
				if (null != countDownListener) {
					if (countSec == sec) {
						countSec -= 1;
						countDownListener.heartBest();
					}
				}
			}

		}

		@Override
		public void onFinish() {
			mTvDaoJiShi.setText("00:00:00");
			mTvDaoJiShi.setVisibility(View.INVISIBLE);
			mTvDaoJiInfo.setText(getString(R.string.text_paying));

			if (null != countDownListener) {
				countDownListener.countDownStart();
			}
			// addTip.setVisibility(View.GONE);
		}
	}

	class TimeEndCount extends CountDownTimer {

		public TimeEndCount(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);

		}

		@Override
		public void onTick(long millisUntilFinished) {

		}

		@Override
		public void onFinish() {
			mTvDaoJiShi.setVisibility(View.INVISIBLE);
			mTvDaoJiInfo.setText(getString(R.string.text_rob_end));
			if (null != countDownListener) {
				countDownListener.countDownEnd();
			}
		}
	}

	/**
	 * 抢购活动的商品详情
	 */
	private void loadProductTopicDetail() {
		HttpClientAsync clientAsync = HttpClientAsync.getInstance();
		HttpParams params = new HttpParams();
		params.put("barId", mBarId);
		params.put("topicId", mTopicId);
		if (ShareCookie.isLoginAuth()) {
			params.put("token", ShareCookie.getToken());
		} else {
			params.put("token", "");
		}
		params.put("signature", "");
		clientAsync.get(HttpUrl.getUrl(HttpUrl.PRODUCTTOPICDETAIL), params, new HttpCallBack() {
			@Override
			public void onHttpSuccess(Object arg0) {
				dismissWaitingDialog();
				ProductTopicModel model = (ProductTopicModel) arg0;
				if (null != model && null != model.getProduct()) {
					mProductModel = model.getProduct();
					mTopDotPager.updateViews(mProductModel.getProductImages());
					loadListOfWinners();
					initViewData();
				}
				if (null != model && null != model.getActivities()) {
					mActivityModels = model.getActivities();
					mListView.setForeShow(mActivityModels);
					if (null != mActivityModels && mActivityModels.size() > 0) {
						mActivityModel = mActivityModels.get(0);
						initTimer(mActivityModel.getStartTime(), mActivityModel.getEndTime(),
								mActivityModel);
					}
				}
				mLLTimeLayout.setVisibility(View.VISIBLE);
				initReLayout();
			}

			@Override
			public void onHttpStarted() {
				showWaitingDialog();
			}

			@Override
			public void onHttpFailure(Exception arg0, String arg1) {
				// mListView.onRefreshFinish();
				// mListView.onLoadFinish();
				dismissWaitingDialog();
				if (StringUtils.isEmpty(arg1)) {
					arg1 = getStringValue(R.string.info_net_error);
				}
				ToastUtils.showMessage(arg1);
			}
		}, ProductTopicModel.class, true);

	}

	/**
	 * 活动预告
	 */
	private void loadProductActivities() {
		HttpClientAsync clientAsync = HttpClientAsync.getInstance();
		HttpParams params = new HttpParams();
		params.put("barId", mBarId);
		params.put("topicId", mTopicId);
		clientAsync.get(HttpUrl.getUrl(HttpUrl.PRODUCTACTIVITIES), params, new HttpCallBack() {

			@Override
			public void onHttpSuccess(Object arg0) {
				ActivityEntity entity = (ActivityEntity) arg0;
				if (null != entity && null != entity.getData()) {
					ArrayList<ActivityModel> mActivityModel = entity.getData();
					mListView.setForeShow(mActivityModel);
				}
			}

			@Override
			public void onHttpStarted() {
			}

			@Override
			public void onHttpFailure(Exception arg0, String arg1) {
				if (StringUtils.isEmpty(arg1)) {
					arg1 = getStringValue(R.string.info_net_error);
				}
				ToastUtils.showMessage(arg1);
			}
		}, ActivityEntity.class);

	}

	/**
	 * 收藏帖子 collectType 0活动贴1话题贴
	 */
	private void loadCollectTopic() {
		if (!ShareCookie.isLoginAuth()) {
			showActivity(ActLogin.class, false);
			return;
		}
		HttpClientAsync clientAsync = HttpClientAsync.getInstance();
		HttpParams params = new HttpParams();
		params.put("barId", mBarId);
		params.put("topicId", mTopicId);
		params.put("token", ShareCookie.getToken());
		params.put("collectType", "0");
		clientAsync.post(HttpUrl.getUrl(HttpUrl.COLLECTTOPIC), params, new HttpCallBack() {

			@Override
			public void onHttpSuccess(Object arg0) {
				dismissWaitingDialog();
				ToastUtils.showMessage(getStringValue(R.string.info_CollectTopic_ok));
			}

			@Override
			public void onHttpStarted() {
				showWaitingDialog();
			}

			@Override
			public void onHttpFailure(Exception arg0, String arg1) {
				dismissWaitingDialog();
				if (StringUtils.isEmpty(arg1)) {
					arg1 = getStringValue(R.string.info_net_error);
				}
				ToastUtils.showMessage(arg1);
			}
		}, BaseEntity.class);

	}

	/**
	 * 抢购商品
	 */
	private void loadRushToGetProduct(String activityId) {
		if (!ShareCookie.isLoginAuth()) {
			showActivity(ActLogin.class, false);
			return;
		}
		HttpClientAsync clientAsync = HttpClientAsync.getInstance();
		HttpParams params = new HttpParams();
		params.put("activityId", activityId);
		params.put("token", ShareCookie.getToken());
		clientAsync.post(HttpUrl.getUrl(HttpUrl.RUSHTOGETPRODUCT), params, new HttpCallBack() {
			@Override
			public void onHttpSuccess(Object arg0) {
				dismissWaitingDialog();
				BaseDataEntity entity = (BaseDataEntity) arg0;
				if (null != entity && !StringUtils.isEmpty(entity.getData())) {
					Intent intent = new Intent(ActActiveDetail.this,ActActiveShare.class);
					if(entity.getState()==1){
						intent.putExtra(Constants.DATA, mProductModel);
						intent.putExtra(Constants.TYPE, ActActiveShare.WIN);
						intent.putExtra(Constants.LOGID, entity.getData());
						mQGouButton.setOnClickListener(new EndListener());
					}else {
						intent.putExtra(Constants.TYPE, ActActiveShare.LOSE);
						mQGouButton.setOnClickListener(new EndListener());
					}
					startActivity(intent);
				}else {
					mQGouButton.setOnClickListener(new StartListener());
					ToastUtils.showMessage(getStringValue(R.string.info_net_error));
				}
			}

			@Override
			public void onHttpStarted() {
				showWaitingDialog();
			}

			@Override
			public void onHttpFailure(Exception arg0, String arg1) {
				dismissWaitingDialog();
				mQGouButton.setOnClickListener(new StartListener());
				if (StringUtils.isEmpty(arg1)) {
					arg1 = getStringValue(R.string.info_net_error);
				}
				ToastUtils.showMessage(arg1);
			}
		}, BaseDataEntity.class);

	}

	/**
	 * 发评论 / 回复别人
	 */
	private void loadReplyTheProductTopic(String replyContent) {
		if (!ShareCookie.isLoginAuth()) {
			showActivity(ActLogin.class, false);
			return;
		}
		HttpClientAsync clientAsync = HttpClientAsync.getInstance();
		HttpParams params = new HttpParams();
		params.put("barId", mBarId);
		params.put("topicId", mTopicId);
		params.put("replyId", "");
		params.put("token", ShareCookie.getToken());
		params.put("location", "");
		params.put("replyContent", replyContent);
		params.put("replyImages", "");
		params.put("signature", "");
		clientAsync.post(HttpUrl.getUrl(HttpUrl.REPLYTHEPRODUCTTOPIC), params, new HttpCallBack() {

			@Override
			public void onHttpSuccess(Object arg0) {
				BaseEntity entity = null;
				try {
					entity = JSONObject.parseObject((String) arg0, BaseEntity.class);
				} catch (Exception e) {
				}
				if (null != entity) {
					if (entity.getState() == 1) {
						mEditText.setText("");
						ToastUtils.showMessage(getStringValue(R.string.info_Reply_ok));
					} else {
						ToastUtils.showMessage(getStringValue(R.string.info_net_error));

					}
				}
			}

			@Override
			public void onHttpStarted() {
			}

			@Override
			public void onHttpFailure(Exception arg0, String arg1) {
				if (StringUtils.isEmpty(arg1)) {
					arg1 = getStringValue(R.string.info_net_error);
				}
				ToastUtils.showMessage(arg1);
			}
		});

	}

	/**
	 * 商品评论列表
	 */
	private void loadProductTopicReplies() {
		HttpClientAsync clientAsync = HttpClientAsync.getInstance();
		HttpParams params = new HttpParams();
		params.put("barId", mBarId);
		params.put("topicId", mTopicId);
		params.put("pageIndex", mPageIndex);
		params.put("pageSize", Constants.PAGE_SIZE);
		clientAsync.post(HttpUrl.getUrl(HttpUrl.PRODUCTTOPICREPLIES), params, new HttpCallBack() {
			@Override
			public void onHttpSuccess(Object arg0) {
				ReplyEntity entity = (ReplyEntity) arg0;
				if (null != entity && null != entity.getData()) {
					mReplyModels = entity.getData();
					mAdapter.putData(mReplyModels);
					mPageIndex += 1;
				}
			}

			@Override
			public void onHttpStarted() {
			}

			@Override
			public void onHttpFailure(Exception arg0, String arg1) {
				if (StringUtils.isEmpty(arg1)) {
					arg1 = getStringValue(R.string.info_net_error);
				}
				ToastUtils.showMessage(arg1);
			}
		}, ReplyEntity.class);

	}

	/**
	 * 中奖名单
	 */
	private void loadListOfWinners() {
		HttpClientAsync clientAsync = HttpClientAsync.getInstance();
		HttpParams params = new HttpParams();
		if(null==mProductModel){
			return;
		}
		params.put("productId", mProductModel.getProductId());
		clientAsync.get(HttpUrl.getUrl(HttpUrl.LISTOFWINNERS), params, new HttpCallBack() {

			@Override
			public void onHttpSuccess(Object arg0) {
				SimpleUserEntity entity = (SimpleUserEntity) arg0;
				if (null != entity && null != entity.getData()) {
					mUserModels = entity.getData();
					if (mUserModels.size() > 0) {
						BaHeaderAdapter adapter = new BaHeaderAdapter(ActActiveDetail.this,
								mUserModels);
						mHorizontalListView.setAdapter(adapter);
					}
				} else {

				}
			}

			@Override
			public void onHttpStarted() {
			}

			@Override
			public void onHttpFailure(Exception arg0, String arg1) {
				if (StringUtils.isEmpty(arg1)) {
					arg1 = getStringValue(R.string.info_net_error);
				}
				ToastUtils.showMessage(arg1);
			}
		}, SimpleUserEntity.class);

	}

}
